﻿Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports Microsoft.ApplicationBlocks.Data
Imports DotNetNuke.Common.Utilities
Imports DotNetNuke.Framework.Providers

Public Class SqlDataProviderHelper

    Private ReadOnly lConnectionString As String

    Public Function AddContact(Contact As Contact) As Integer
        Dim converter As New ContactToSQLParameterConverter
        Return Convert.ToInt32(SqlHelper.ExecuteScalar(lConnectionString, CommandType.StoredProcedure, "Geminorum_Contact_Insert", converter.GetInsertParameterList(Contact).ToArray))
    End Function

    Public Sub DeleteContact(ContactID As Integer)
        SqlHelper.ExecuteNonQuery(lConnectionString, CommandType.StoredProcedure, "Geminorum_Contact_DeleteByID", {New SqlParameter("@ID", ContactID)})
    End Sub

    Public Sub DeleteContacts(ModuleID As Integer)
        SqlHelper.ExecuteNonQuery(lConnectionString, CommandType.StoredProcedure, "Geminorum_Contact_DeleteByModuleID", {New SqlParameter("@ModuleID", ModuleID)})
    End Sub

    Public Function GetContact(ContactID As Integer) As IDataReader
        Return SqlHelper.ExecuteReader(lConnectionString, CommandType.StoredProcedure, "Geminorum_Contact_SelectByID", {New SqlParameter("@ID", ContactID)})
    End Function

    Public Function GetContacts(ModuleID As Integer) As IDataReader
        Return SqlHelper.ExecuteReader(lConnectionString, CommandType.StoredProcedure, "Geminorum_Contact_SelectByModuleID", {New SqlParameter("@ModuleID", ModuleID)})
    End Function

    Public Sub UpdateContact(Contact As Contact)
        Dim converter As New ContactToSQLParameterConverter
        SqlHelper.ExecuteNonQuery(lConnectionString, CommandType.StoredProcedure, "Geminorum_Contact_Update", converter.GetUpdateParameterList(Contact).ToArray)
    End Sub

    Sub New(ConnectionString As String)
        lConnectionString = ConnectionString
    End Sub
End Class